package com.atguigu.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.yygh.cmn.mapper.DictMapper;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.vo.cmn.DictEeVo;
import org.apache.commons.collections4.BagUtils;
import org.springframework.beans.BeanUtils;

public class DickListener extends AnalysisEventListener<DictEeVo> {

    private DictMapper dictMapper;

    public DickListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    //一行行读取
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        //调方法添加到数据库
        dictMapper.insert(dictEeVoToDict(dictEeVo));
    }

    //转化dictEe->Dict
    private Dict dictEeVoToDict(DictEeVo dictEeVo) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo, dict);
        return dict;
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
